local sheren = fk.CreateSkill {
  name = "lingling__sheren",
}

Fk:loadTranslationTable {
  ["lingling__sheren"] = "舍仁",
  [":lingling__sheren"] = "回合结束时，你可以获得两张不计入手牌上限的【闪】，然后失去1点体力。你可以将两张【闪】当【桃】使用，然后目标摸一张牌。",

  ["#lingling__sheren"] = "舍仁：你可以将两张【闪】当【桃】使用，目标摸一张牌",
  ["#lingling__sheren-invoke"] = "舍仁：你可以获得两张【闪】，然后失去1点体力",
  ["@@lingling__sheren-inhand"] = "舍仁",
}

sheren:addEffect("viewas", {
  anim_type = "support",
  pattern = "peach",
  prompt = "#lingling__sheren",
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected < 2 and Fk:getCardById(to_select).trueName == "jink"
  end,
  view_as = function(self, player, cards)
    if #cards ~= 2 then return end
    local card = Fk:cloneCard("peach")
    card.skillName = sheren.name
    card:addSubcards(cards)
    return card
  end,
  after_use = function(self, player, use)
    for _, p in ipairs(player.room:getAlivePlayers()) do
      if not p.dead and table.contains(use.tos, p) then
        p:drawCards(1, sheren.name)
      end
    end
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end,
})

sheren:addEffect(fk.TurnEnd, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sheren.name) and player.hp > 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = sheren.name,
      prompt = "#lingling__sheren-invoke",
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getCardsFromPileByRule("jink", 2, "allPiles")
    if #cards > 0 then
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, sheren.name, nil, true, player,
        "@@lingling__sheren-inhand")
    end
    if player.dead then return end
    room:loseHp(player, 1, sheren.name)
  end,
})

sheren:addEffect("maxcards", {
  exclude_from = function(self, player, card)
    return card:getMark("@@lingling__sheren-inhand") > 0
  end,
})

sheren:addAI(nil, "vs_skill")

return sheren
